package cn.fancylab.template.web.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;

import cn.fancylab.Config;
import cn.fancylab.SysConfig;
import cn.fancylab.util.LoggerUtils;
import cn.fancylab.util.ObjectId;

public class StartupListener extends ContextLoaderListener {
	private Logger logger = LoggerUtils.getLogger(getClass());

	@Override
	public void contextInitialized(ServletContextEvent event) {
		String SPRING_CONFIG_KEY = "contextConfigLocation";
		String[] config = new String[] { "classpath:spring/appContext-*.xml" };

		String SPRING_CONFIG_VALUE = StringUtils.join(config, ",");

		logger.warn("Config Using Config:{}, Spring={}", SysConfig.CFG_LOCATION, SPRING_CONFIG_VALUE);
		ServletContext context = event.getServletContext();
		context.setInitParameter(SPRING_CONFIG_KEY, SPRING_CONFIG_VALUE);
		super.contextInitialized(event);
		logger.warn("INIT GLOCAL PAGE-TOOLS: " + Config.getPageTools());
		logger.warn("INIT OBJECTID:" + ObjectId.get().toString());
	}
}
